// ==UserScript==
// @name         映翠停车系统
// @namespace    http://tampermonkey.net/
// @version      2025-07-14
// @description  2025-06-14第一版本
// @author       You
// @match        http://i2.128d.com/Parent/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=128d.com
// @grant        none
// ==/UserScript==

(function() {
	'use strict';
	//油猴脚本
	var form1 = document.getElementById("form1")
	form1.innerHTML = "";
	var div1 = document.createElement("div");
	div1.className = "row";
	div1.innerHTML = '<input id="youhou_ParkCode" type="text" placeholder="车场名称" value="zsycht">';
	form1.appendChild(div1);

	var div2 = document.createElement("div");
	div2.className = "row";
	div2.innerHTML = '<input id="youhou_plate" type="text" placeholder="车牌号码" value="粤T999CC">';
	form1.appendChild(div2);

	var div3 = document.createElement("div");
	div3.className = "row";
	div3.innerHTML = '<button id="youhou_GetPayUrl" type="button"><span>获取支付链接</span></button>';
	form1.appendChild(div3);

	var div4 = document.createElement("div");
	div4.className = "row";
	div4.innerHTML = '<textarea id="youhou_PayUrl" rows="10" cols="50"></textarea>';
	form1.appendChild(div4);

	var div5 = document.createElement("div");
	div5.className = "row";
	div5.innerHTML = '<button id="youhou_copy" type="button"><span>复制链接</span></button>';
	form1.appendChild(div5);

	$("#youhou_GetPayUrl").click(
		function() {
			var ParkCode = document.getElementById("youhou_ParkCode").value
			var plate = document.getElementById("youhou_plate").value
			$.ajax({
				url: "/mapi/CarList/index.ashx",
				data: {
					ParkCode: ParkCode,
					plate: plate
				},
				type: "post",
				dataType: "json",
				success: function(res1) {
					if (res1.Status == "") {
						$.ajax({
							url: '/mapi/payinfo.ashx?num=' + Math.random(),
							data: {
								Action: "CreateOrder",
								ParkCode: ParkCode,
								PayPlate: plate,
								PayMent: 500, //转为分（100分即为1元）
								PMD5: res1.Data[0].PicName,
								PayType: "EPay"
							},
							type: "post",
							dataType: "json",
							success: function(res) {
								var outputRes = ""
								if (res.Status == "") {
									console.log(encodeURI(res.Data.PayUrl));
									outputRes = encodeURI(res.Data.PayUrl)
								} else {
									console.log(res.Status)
									outputRes = res.Status
								}
								document.getElementById("youhou_PayUrl").value = outputRes
							}
						});
					} else {
						console.log(res1.Status)
					}
				}
			});
		}
	);

	$("#youhou_copy").click(
		function() {
			let copy = (e) => {
				e.preventDefault()
				e.clipboardData.setData('text/plain', '<a href="'+document.getElementById("youhou_PayUrl").value+'">停车支付</a>')
				$.login.formMessage("复制成功")
				document.removeEventListener('copy', copy)
			}
			document.addEventListener('copy', copy)
			document.execCommand("Copy");
            window.location.href = "weixin://";//打开微信
		}
	);
})();